package com.daxue.commons.data;

import lombok.extern.slf4j.Slf4j;
import org.jooq.codegen.GenerationTool;
import org.jooq.meta.jaxb.Configuration;
import org.jooq.meta.jaxb.Database;
import org.jooq.meta.jaxb.Generator;
import org.jooq.meta.jaxb.Jdbc;
import org.jooq.meta.jaxb.Target;
import org.junit.jupiter.api.Test;
/**
 * @author daxue0929
 * @date 2023/4/20
 */
@Slf4j
public class GenerateCode {
    @Test
    public void context() {
        log.info("context...");
    }

    @Test
    public void generate() throws Exception {
        Configuration configuration = new Configuration()
            .withJdbc(new Jdbc()
                .withDriver("org.postgresql.Driver")
                .withUrl("jdbc:postgresql://localhost:5432/app_config?useJDBCCompliantTimezoneShift=true&amp;serverTimezone=UTC&amp;useSSL=false")
                .withUser("postgres")
                .withPassword("123456"))

            .withGenerator(new Generator()
                .withDatabase(new Database()
                    .withName("org.jooq.meta.postgres.PostgresDatabase")
                    .withIncludes("config")
                    .withExcludes("")
                    .withIncludePrimaryKeys(true)
                    .withInputSchema("public"))
                .withTarget(new Target()
                    .withPackageName("com.daxue.commons.test") //com.daxue.configtest.config.repository.dao
                    .withDirectory("src/main/java")
                    .withClean(false))
//                .withGenerate(new Generate()
//                    .withPojos(true).withPojosToString(true)
//                    .withRecords(false).withTables(false).withIndexes(false).withKeys(false)
//                    .withEmptyCatalogs(true)
//                    .withEmptySchemas(true)
//                )
            );
        GenerationTool.generate(configuration);
    }
}
